<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="copyright" content="http://www.appcms.org" />
<link rel="stylesheet" href="skin/base.css">
<link rel="stylesheet" href="skin/btn.css">
<link rel="stylesheet" href="skin/activity.css">
<script src="js/zy_control.js"></script>
<script src="js/zy_click.js"></script>
<script src="js/config.js"></script>
<script src="js/common.js"></script>
</head>
<body>
<div id="main" class="loading"></div>
</body>
<script>
	zy_init();
	var price = '';
	function orders(t){		
		if (c_l()) {
			if (!localStorage['u_mobile']) {
				uexWindow.alert('错误提示', '请先在会员中心绑定手机号码~', '确定');
				return false;
			}
			
			uexWindow.cbActionSheet = function(opId,dataType,data){
				if(dataType==2){
					if(data==0){
						uexWindow.toast(1, 5, '兑换中，请稍候...', 0);
						var url = app_path+'index.php?m=iappJifen&c=app&a=orders&id='+localStorage['jifen_id']+'&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];
						uexXmlHttpMgr.open(2,'post',url,"8000");
						uexXmlHttpMgr.send(2);
					}
				}
			}
			uexWindow.actionSheet('你确定要使用'+price+l_common['head_txt_integral']+'兑换吗？','取消',['确定兑换']);
		
		}else{
			gologin();
		}
		
	}
	
	function getMain(){
		var url = app_path+'index.php?m=iappJifen&c=app&a=show&id='+localStorage['jifen_id'];
		uexXmlHttpMgr.open(1,'post',url,"8000");
		uexXmlHttpMgr.send(1);
	}
	
	window.uexOnload=function(type){
		if(!type){
			
			uexWindow.setBounce("1");
			uexWindow.showBounceView("0","#666","0");
			uexWindow.showBounceView("1","#666","0");
			
			uexXmlHttpMgr.onData = function(opId, status, data){
				if (opId == 1) {
					if(status==1){			
						uexXmlHttpMgr.close(opId);
						uexWindow.resetBounceView(opId);
						data = JSON.parse(data);
						if(data['status']=='OK'){
							var item=data['data'];
							
							price = item['price'];
							
							var div='<div class="show">';
							div+='<div class="loadimg"><img src="'+item['image']+'" class="hide" onload="this.className=\'\'" /></div>'+
							'<h1>'+item['title']+'</h1>'+
							'<h3>兑换价格：<span>'+item['price']+l_common['head_txt_integral']+'</span><em id="stock">库存：'+item['stock']+'</em></h3>'+
							'<div class="btn pb" ><div class="button" onclick="orders(this);" >马上兑换</div></div>';
							for (i in item['specifications']) {
								div+='<h3>'+item['specifications'][i]['title']+'</h3><pre>'+item['specifications'][i]['description']+'</pre>';
							}
							
							div+='</div>';			
							$$("main").className = '';
							$$("main").innerHTML=div;
						}else{
							uexWindow.alert('错误提示',data['msg'],'确定');
							uexWindow.evaluateScript('jifen_show',0,"uexWindow.close(-1);");
						}
					}else if(status ==-1) {
						uexWindow.toast("0","5",'加载失败,请点击重新加载',1000);
						$$("main").className='errer';
						$$('main').setAttribute("onclick", "javascript:getMain();"); 
					}
				}else if(opId == 2){
					uexWindow.closeToast();
					uexXmlHttpMgr.close(opId);
					if(status==1){
						data = JSON.parse(data);	
						if(data['status']=='OK'){
							$$('stock').innerHTML='库存：'+data['stock'];
							uexWindow.alert('兑换成功',data['msg'],'确定');
						}else if(data['status']=='NOTLOGIN'){
							gologin()
						}else{
							uexWindow.alert('兑换失败',data['msg'],'确定');
						}
					}else if(status ==-1) {
						uexWindow.alert('兑换失败','网络异常，请重新操作','确定');
					}
				}
			}
			
			getMain();			
		}
	}
	</script>
</html>